package com.example.neusoft.yuejian.Activity;


import android.content.Context;
import android.content.SharedPreferences;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.neusoft.yuejian.Base.BaseActivity;
import com.example.neusoft.yuejian.Base.BaseListener;
import com.example.neusoft.yuejian.Base.BaseModel;
import com.example.neusoft.yuejian.Bean.ActBean;
import com.example.neusoft.yuejian.Bean.ActDetailBean;
import com.example.neusoft.yuejian.Bean.ActenrollBean;
import com.example.neusoft.yuejian.Bean.MyBean;
import com.example.neusoft.yuejian.R;


import retrofit2.Call;

public class ActEnrollActivity extends BaseActivity implements View.OnClickListener{
    private ActDetailBean act;
    private MyBean mine;
    private TextView hdmc,yhmz,lxfs,hdjg,hdsj,hddz;
    private Button qrbm;
    private Context context;
    private SharedPreferences sp ;
    private int id,uid;
    private ImageView fh;
    @Override
    public int getLayoutFile() {
        return R.layout.act_enroll;
    }

    @Override
    public void initView() {
        hddz=(TextView)findViewById(R.id.hddz);
        yhmz=(TextView)findViewById(R.id.yhmz);
        hdmc=(TextView)findViewById(R.id.hdmc);
        lxfs=(TextView)findViewById(R.id.lxfs);
        hdjg=(TextView)findViewById(R.id.hdjg);
        hdsj=(TextView)findViewById(R.id.hdsj);
        qrbm=(Button) findViewById(R.id.qrbm);
        fh=(ImageView)findViewById(R.id.fh);

    }

    @Override
    public void initEvent() {
     qrbm.setOnClickListener(this);
     fh.setOnClickListener(this);
    }


    @Override
    public void initData() {
        act=(ActDetailBean) getIntent().getSerializableExtra("aid");
        context=ActEnrollActivity.this;
        sp=context.getSharedPreferences("User", context.MODE_PRIVATE);
        uid= sp.getInt("id",0);
        hdmc.setText(act.getAname());
        hdjg.setText(act.getAprice());
        hddz.setText(act.getAaddress());
        hdsj.setText(act.getAstarttime());
        id=act.getAid();
        getMine(uid);

    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.qrbm:
                getenroll(id,uid);
                break;
            case R.id.fh:
                finish();
                break;
        }
    }
    public void getenroll(int id,int uid){
        BaseModel<ActenrollBean> model=new BaseModel<>();
        Call<ActenrollBean> call=model.service.getactenroll(id,uid);
        model.callEnqueue(call,listener);
    }
    BaseListener<ActenrollBean> listener=new BaseListener<ActenrollBean>() {
        @Override
        public void onResponse(ActenrollBean actenrollbean) {
            if(actenrollbean.getStatus()==1){
                showToast(actenrollbean.getMessage());

            }else{
                showToast(actenrollbean.getMessage());

            }
        }

        @Override
        public void onFail(String message) {
            showToast("123");
        }
    };
    private void getMine(int uid ){
        BaseModel<MyBean> model = new BaseModel<>();
        Call<MyBean> call = model.service.getMine(uid);
        model.callEnqueue(call, list);
    }
    BaseListener<MyBean> list=new BaseListener<MyBean>() {
        @Override
        public void onResponse(MyBean myBean) {
            mine=myBean;
           yhmz.setText(myBean.getUname());
        }

        @Override
        public void onFail(String msg) {

        }
    };
  }

